********************************************************************************
**** Covid-19 Crisis and Hostility against Foreigners 
**** Figures
*******************************************************************************

log using "$logpath/03_figures", replace

***************************************************************************************************
**** Figure 1A: Main specification
***************************************************************************************************
{
use "$cleandatapath/covid_fuels_hostility_clean_long.dta", clear
* CZ
quietly eststo main_cz: reg HHT covid_prime $basic_controls if type_index=="DOMESTIC", cluster(respondentId)
sum HHT if !covid_prime & type_index=="DOMESTIC"
scalar main_cz_mean = r(mean)
* Foreign
quietly eststo main_foreign: reg HHT covid_prime $basic_controls if type_index=="FOREIGN", cluster(respondentId)
* EU
quietly eststo main_eu: reg HHT covid_prime $basic_controls if type_group=="EU", cluster(respondentId)
* USA
quietly eststo main_usa: reg HHT covid_prime $basic_controls if type_group=="USA", cluster(respondentId)
* Africa
quietly eststo main_africa: reg HHT covid_prime $basic_controls if type_group=="Africa", cluster(respondentId)
* Asia
quietly eststo main_asia: reg HHT covid_prime $basic_controls if type_group=="Asia", cluster(respondentId)

coefplot ///
	main_cz || ///
	main_foreign || ///
	main_asia || ///
	main_eu || ///
	main_usa || ///
	main_africa || ///
	, ///
	xline(0, lpattern(dash)) ///
	mcolor(black) msymbol(circle) ///
	mlabel(string(@b,"%9.1f")) format(%9.2g) mlabposition(12) mlabgap(*2) ///
	bylabels( "Domestic recipient" "Foreign recipient" "Asian recipient" "EU recipient" "US recipient" "African recipient") ///
	xtitle("Effect of COVID-19 condition on the amount allocated (CZK)") ///
	bycoefs ///
	grid(none) ///
	fxsize(120) ///
	keep(covid_prime) legend(off)
	
graph save "$outputpath/Figures/Fig1A", replace
graph export "$outputpath/Figures/Fig1A.png", replace
}
	

***************************************************************************************************
**** Figure 1B: Dummies for hostile behavior 
***************************************************************************************************
{
use "$cleandatapath/covid_fuels_hostility_clean_long.dta", clear

eststo clear
* CZ, antisocial
quietly eststo dum_cz_anti: reg antisocial covid_prime $basic_controls if type_index=="DOMESTIC", cluster(respondentId)
* CZ, altruistic
quietly eststo dum_cz_altr: reg altruistic covid_prime $basic_controls if type_index=="DOMESTIC", cluster(respondentId)
* Foreign, antisocial
quietly eststo dum_foreign_anti: reg antisocial covid_prime $basic_controls if type_index=="FOREIGN", cluster(respondentId)
* Foreign, altruistic
quietly eststo dum_foreign_altr: reg altruistic covid_prime $basic_controls if type_index=="FOREIGN", cluster(respondentId)
* EU, antisocial
quietly eststo dum_eu_anti: reg antisocial covid_prime $basic_controls if type_group=="EU", cluster(respondentId)
* EU, altruistic
quietly eststo dum_eu_altr: reg altruistic covid_prime $basic_controls if type_group=="EU", cluster(respondentId)
* USA, antisocial
quietly eststo dum_usa_anti: reg antisocial covid_prime $basic_controls if type_group=="USA", cluster(respondentId)
* USA, altruistic
quietly eststo dum_usa_altr: reg altruistic covid_prime $basic_controls if type_group=="USA", cluster(respondentId)
* Africa, antisocial
quietly eststo dum_africa_anti: reg antisocial covid_prime $basic_controls if type_group=="Africa", cluster(respondentId)
* Africa, altruistic
quietly eststo dum_africa_altr: reg altruistic covid_prime $basic_controls if type_group=="Africa", cluster(respondentId)
* Asia, antisocial
quietly eststo dum_asia_anti: reg antisocial covid_prime $basic_controls if type_group=="Asia", cluster(respondentId)
* Asia, altruistic
quietly eststo dum_asia_altr: reg altruistic covid_prime $basic_controls if type_group=="Asia", cluster(respondentId)

coefplot ///
	(dum_cz_anti, label("Hostile (binary)") offset(.0)), bylabel("Domestic recipient") || ///
	(dum_foreign_anti, offset(.0)), bylabel("Foreign recipient") || ///
	(dum_asia_anti, offset(.0)), bylabel("Recipient from Asia") || ///
	(dum_eu_anti, offset(.0)), bylabel("Recipient from EU") || ///
	(dum_usa_anti, offset(.0)), bylabel("Recipient from USA") || ///
	(dum_africa_anti, offset(.0)), bylabel("Recipient from Africa") || ///
	, ///
	xline(0, lpattern(dash)) ///
	mlabel(string(@b,"%9.2f")) format(%9.2g) mlabposition(12) mlabgap(*2) ///
	bycoefs ///
	grid(none) ///
	xtitle("Effect of COVID-19 condition on the probability of hostile behavior") ///
	legend(off) ///
	fxsize(120) ///
	keep(covid_prime)
graph save "$outputpath/Figures/Fig1B", replace
graph export "$outputpath/Figures/Fig1B.png", replace

}

***************************************************************************************************
**** Figure 2: Heterogeneity
***************************************************************************************************
{
use "$cleandatapath/covid_fuels_hostility_clean_long.dta", clear

eststo clear
* Foreign, young
quietly eststo het_foreign_young: reg HHT covid_prime $basic_controls if type_index=="FOREIGN" & age<50, cluster(respondentId)
* EU, young
quietly eststo het_eu_young: reg HHT covid_prime $basic_controls if type_group=="EU" & age<50, cluster(respondentId)
* Foreign, old
quietly eststo het_foreign_old: reg HHT covid_prime $basic_controls if type_index=="FOREIGN" & age>=50, cluster(respondentId)
* EU, old
quietly eststo het_eu_old: reg HHT covid_prime $basic_controls if type_group=="EU" & age>=50, cluster(respondentId)
* Foreign, male
quietly eststo het_foreign_male: reg HHT covid_prime $basic_controls if type_index=="FOREIGN" & female==0, cluster(respondentId)
* EU, male
quietly eststo het_eu_male: reg HHT covid_prime $basic_controls if type_group=="EU" & female==0, cluster(respondentId)
* Foreign, female
quietly eststo het_foreign_female: reg HHT covid_prime $basic_controls if type_index=="FOREIGN" & female==1, cluster(respondentId)
* EU, female
quietly eststo het_eu_female: reg HHT covid_prime $basic_controls if type_group=="EU" & female==1, cluster(respondentId)
* Foreign, high educ
quietly eststo het_foreign_higheduc: reg HHT covid_prime $basic_controls if type_index=="FOREIGN" & educ==4, cluster(respondentId)
* EU, high educ
quietly eststo het_eu_higheduc: reg HHT covid_prime $basic_controls if type_group=="EU" & educ==4, cluster(respondentId)
* Foreign, low educ
quietly eststo het_foreign_loweduc: reg HHT covid_prime $basic_controls if type_index=="FOREIGN" & educ!=4, cluster(respondentId)
* EU, low educ
quietly eststo het_eu_loweduc: reg HHT covid_prime $basic_controls if type_group=="EU" & educ!=4, cluster(respondentId)
* Foreign, high inc
quietly eststo het_foreign_highinc: reg HHT covid_prime $basic_controls if type_index=="FOREIGN" & CNP_hincome>=7, cluster(respondentId)
* EU, high inc
quietly eststo het_eu_highinc: reg HHT covid_prime $basic_controls if type_group=="EU" & CNP_hincome>=7, cluster(respondentId)
* Foreign, low inc
quietly eststo het_foreign_lowinc: reg HHT covid_prime $basic_controls if type_index=="FOREIGN" & CNP_hincome<7, cluster(respondentId)
* EU, low inc
quietly eststo het_eu_lowinc: reg HHT covid_prime $basic_controls if type_group=="EU" & CNP_hincome<7, cluster(respondentId)
* Czech, cities
quietly eststo het_czech_city: reg HHT covid_prime $basic_controls if (type_index=="DOMESTIC") & townsize==7, cluster(respondentId)
* Foreign, cities
quietly eststo het_foreign_city: reg HHT covid_prime $basic_controls if type_index=="FOREIGN" & townsize==7, cluster(respondentId)
* EU, cities
quietly eststo het_eu_city: reg HHT covid_prime $basic_controls if type_group=="EU" & townsize==7, cluster(respondentId)
* Czech, villages/towns
quietly eststo het_czech_village: reg HHT covid_prime $basic_controls if (type_index=="DOMESTIC") & townsize!=7, cluster(respondentId)
* Foreign, villages/towns
quietly eststo het_foreign_village: reg HHT covid_prime $basic_controls if type_index=="FOREIGN" & townsize!=7, cluster(respondentId)
* EU, villages/towns
quietly eststo het_eu_village: reg HHT covid_prime $basic_controls if type_group=="EU" & townsize!=7, cluster(respondentId)


coefplot ///
    (het_eu_young, label(EU recipient) msymbol(O) offset(.10)) ///
	(het_foreign_young, label(FOREIGN recipient) msymbol(Oh) offset(-.10)), bylabel("Younger") || ///
	(het_eu_old,  offset(.10)) ///
	(het_foreign_old,  offset(-.10)), bylabel("Older") || ///
	(het_eu_male,  offset(.10)) ///
	(het_foreign_male,  offset(-.10)), bylabel("Male") || ///
	(het_eu_female,  offset(.10)) ///
	(het_foreign_female,  offset(-.10)), bylabel("Female") || ///
	(het_eu_city, offset(.10)) ///
	(het_foreign_city, offset(-.10)), bylabel("Cities") || ///
	(het_eu_village, offset(.10)) ///
	(het_foreign_village, offset(-.10)), bylabel("Villages and towns") || ///
	(het_eu_higheduc, offset(.10)) ///
	(het_foreign_higheduc, offset(-.10)), bylabel("University education") || ///
	(het_eu_loweduc, offset(.10)) ///
	(het_foreign_loweduc, offset(-.10)), bylabel("Primary/Secondary education") || ///
	(het_eu_highinc, offset(.10)) ///
	(het_foreign_highinc, offset(-.10)), bylabel("Above median income") || ///
	(het_eu_lowinc, offset(.10)) ///
	(het_foreign_lowinc, offset(-.10)), bylabel("Below median income") || ///
	, ///
	xline(0, lpattern(dash)) ///
	bycoefs ///
	grid(none) ///
	xtitle("Effect of COVID-19 condition on the amount allocated (CZK)") ///
	legend(rows(1) position(6))  ///
	ysize(5) xsize(8) ///
	keep(covid_prime) 
graph save "$outputpath/Figures/Fig2", replace
graph export "$outputpath/Figures/Fig2.png", replace
}


***************************************************************************************************
**** Figure 3: Main specification, Domestic
***************************************************************************************************
{
use "$cleandatapath/covid_fuels_hostility_clean_long.dta", clear
*drop if religion==.
global x_controls $basic_controls

*All ingroup outgroup
eststo main_domestic_ingroup : reg HHT covid_prime  $x_controls if type_index=="DOMESTIC ingroup", cluster(respondentId)
eststo main_domestic_outgroup : reg HHT covid_prime  $x_controls if type_index=="DOMESTIC outgroup", cluster(respondentId)
*Region
eststo main_region_ingroup : reg HHT covid_prime  $x_controls if type_group=="Region ingroup", cluster(respondentId)
eststo main_region_outgroup : reg HHT covid_prime  $x_controls if type_group=="Region outgroup", cluster(respondentId)
*Political
eststo  main_political_ingroup  : reg HHT covid_prime  $x_controls if type_group=="Political ingroup", cluster(respondentId)
eststo   main_political_outgroup : reg HHT covid_prime  $x_controls if type_group=="Political outgroup" , cluster(respondentId)
*Ethnicity/Immigrant
eststo  main_majority_ingroup  : reg HHT covid_prime  $x_controls if type_group=="Majority ingroup", cluster(respondentId)
eststo main_ethnicity_outgroup : reg HHT covid_prime  $x_controls if type_group=="Roma outgroup", cluster(respondentId)
eststo  main_immigrant_outgroup : reg HHT covid_prime  $x_controls if type_group=="Immigrant outgroup", cluster(respondentId)
*Religion
eststo main_religion_ingroup : reg HHT covid_prime $x_controls if type_group=="Religion ingroup", cluster(respondentId)
eststo main_religion_outgroup : reg HHT covid_prime  $x_controls if type_group=="Religion outgroup", cluster(respondentId)

coefplot ///
	main_domestic_ingroup|| ///
	main_domestic_outgroup || ///
	 main_region_ingroup  || ///
	 main_region_outgroup || ///
	 main_political_ingroup  || ///
	 main_political_outgroup  || ///
	  main_majority_ingroup   || ///
	 main_ethnicity_outgroup|| ///
	main_immigrant_outgroup   || ///
	 main_religion_ingroup  || ///
	 main_religion_outgroup || ///
	, ///
	xline(0, lpattern(dash)) ///
	mcolor(black) msymbol(circle) ///
	mlabel(string(@b,"%9.1f")) format(%9.2g) mlabposition(12) mlabgap(*2) ///
	bylabels( "Domestic ingroup" "Domestic outgroup" "Region ingroup" "Region outgroup" "Political ingroup" "Political outgroup" "Majority ingroup" "Roma ethnicity outgroup" "Immigrant outgroup"  "Religion ingroup" "Religion outgroup" ) ///
	xscale(r(-15 5)) xlab(-15(10)5) xtitle("Effect of COVID-19 condition on the amount allocated (CZK)") ///
	bycoefs ///
	grid(none) ///
	fxsize(120) ///
	keep(covid_prime) legend(off)
	
graph save "$outputpath/Figures/Fig3", replace
graph export "$outputpath/Figures/Fig3.png", replace

}


***************************************************************************************************
**** Supplementary Figure 2: Histograms/cdfs
***************************************************************************************************
{
****DOMESTIC vs. FOREIGN vs. Asia
	use "$cleandatapath/covid_fuels_hostility_clean_long.dta", clear
	twoway ///
		(histogram HHT if (type_index=="DOMESTIC" & covid_prime==0), ///
			color(gs11) width(10) fraction) ///
		(histogram HHT if (type_index=="DOMESTIC" & covid_prime==1),  /// 
			fcolor(none) lcolor(black) width(10) fraction), ///
		legend(row(1) order(1 "Control" 2 "COVID-19" ) position(6)) title("(a) Domestic") xtitle("Help-or-Harm task allocations") ylabel(,nogrid)
	graph export "$outputpath/Figures/Histogram_domestic.png", as(png) name("Graph") replace
	graph save "$outputpath/Figures/Histogram_domestic.gph", replace
	twoway (histogram HHT if (type_index=="FOREIGN" & covid_prime==0),  color(gs11) width(10) fraction) ///
		   (histogram HHT if (type_index=="FOREIGN" & covid_prime==1),  fcolor(none) lcolor(black) width(10) fraction), legend(row(1) order(1 "Control" 2 "COVID-19" ) position(6)) title("(b) Foreign") xtitle("Help-or-Harm task allocations") ylabel(,nogrid)
	graph export "$outputpath/Figures/Histogram_foreign.png", as(png) name("Graph") replace
	graph save "$outputpath/Figures/Histogram_foreign.gph", replace
	twoway (histogram HHT if (type_group=="Asia" & covid_prime==0),  color(gs11) width(10) fraction) ///
		   (histogram HHT if (type_group=="Asia" & covid_prime==1),  fcolor(none) lcolor(black) width(10) fraction), legend(row(1) order(1 "Control" 2 "COVID-19" ) position(6)) xtitle("Help-or-Harm task allocations") title("(c) Asian")  ylabel(,nogrid)
	graph export "$outputpath/Figures/Histogram_asia.png", as(png) name("Graph") replace
	graph save "$outputpath/Figures/Histogram_asia.gph", replace

	grc1leg "$outputpath/Figures/Histogram_domestic.gph" "$outputpath/Figures/Histogram_foreign.gph" "$outputpath/Figures/Histogram_asia.gph", ///
		ycommon xcommon ///
		commonscheme ///
		legendfrom("$outputpath/Figures/Histogram_domestic.gph") ///
		rows(1) ///
		xsize(12) 
	graph save "$outputpath/Figures/FigS2_abc.gph", replace
	graph export "$outputpath/Figures/FigS2_abc.png", replace


****EU vs. USA vs. Africa

use "$cleandatapath/covid_fuels_hostility_clean_long.dta", clear
twoway ///
	(histogram HHT if (type_group=="EU" & covid_prime==0), ///
		color(gs11) width(10) fraction) ///
	(histogram HHT if (type_group=="EU" & covid_prime==1),  /// 
		fcolor(none) lcolor(black) width(10) fraction), ///
	legend(row(1) order(1 "Control" 2 "COVID-19" ) position(6)) title("(d) European Union") xtitle("Help-or-Harm task allocations") ylabel(,nogrid)
graph export "$outputpath/Figures/Histogram_EU.png", as(png) name("Graph") replace
graph save "$outputpath/Figures/Histogram_EU.gph", replace
twoway (histogram HHT if (type_group=="USA" & covid_prime==0),  color(gs11) width(10) fraction) ///
       (histogram HHT if (type_group=="USA" & covid_prime==1),  fcolor(none) lcolor(black) width(10) fraction), legend(row(1) order(1 "Control" 2 "COVID-19" ) position(6)) title("(e) United States") xtitle("Help-or-Harm task allocations") ylabel(,nogrid)
graph export "$outputpath/Figures/Histogram_USA.png", as(png) name("Graph") replace
graph save "$outputpath/Figures/Histogram_USA.gph", replace
twoway (histogram HHT if (type_group=="Africa" & covid_prime==0),  color(gs11) width(10) fraction) ///
       (histogram HHT if (type_group=="Africa" & covid_prime==1),  fcolor(none) lcolor(black) width(10) fraction), legend(row(1) order(1 "Control" 2 "COVID-19" ) position(6)) xtitle("Help-or-Harm task allocations") title("(f) African")  ylabel(,nogrid)
graph export "$outputpath/Figures/Histogram_africa.png", as(png) name("Graph") replace
graph save "$outputpath/Figures/Histogram_africa.gph", replace

grc1leg "$outputpath/Figures/Histogram_EU.gph" "$outputpath/Figures/Histogram_USA.gph" "$outputpath/Figures/Histogram_Africa.gph", ///
	ycommon xcommon ///
	commonscheme ///
	legendfrom("$outputpath/Figures/Histogram_EU.gph") ///
	rows(1) ///
	xsize(12) 
graph save "$outputpath/Figures/FigS2_def.gph", replace
graph export "$outputpath/Figures/FigS2_def.png", replace



}
***************************************************************************************************
**** Supplementary Figure 3: Covid cases in the Czech Republic
***************************************************************************************************
{
use "$cleandatapath/covid_cases_CZ_by_date_MZCR.dta", clear


twoway (tsline cases) if type==1, xtitle("") ytitle("Number of confirmend cases") xsize(6) ylabel(0(1000)7000) xlabel(21941(5)22028, ang(70)) xline(22004, lp(dash) lcolor(red)) xline(22006, lp(dash) lcolor(red)) text(5500 21995 "Data collection", color(red))

graph save "$outputpath/Figures/FigS3.gph", replace
graph export "$outputpath/Figures/FigS3.png", replace
}

log close
